﻿using System.Web.Mvc;
using System.Web.Security;
using Data;

namespace Web.Filters
{
    public class UpdateLastVisitAttribute : AuthorizeAttribute
    {
        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            var cookie = filterContext.HttpContext.Request.Cookies[FormsAuthentication.FormsCookieName];
            if (cookie != null)
            {
                var auth = FormsAuthentication.Decrypt(cookie.Value);
                var dbUsers = new UsersData();
                dbUsers.UpdateLastVisit(login: auth.Name);
            }
        }
    }
}